package com.cskt.petproject178.handler;

import com.cskt.petproject178.pojo.exception.BaseException;
import com.cskt.petproject178.pojo.vo.ResultStatusEnum;
import com.cskt.petproject178.pojo.vo.ResultVO;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 *
 * @author 27013
 **/

@RestControllerAdvice
public class GlobalExceptionInterceptor{

    private static final Logger log = LogManager.getLogger(GlobalExceptionInterceptor.class);

    @ExceptionHandler(BaseException.class)
    public ResultVO<Void> baseException(BaseException e){
        log.error("统一的异常处理器",e);
        return ResultVO.ERR(e.getCode(),e.getMessage());
    }
    @ExceptionHandler(RuntimeException.class)
    public ResultVO<Void> handlerRuntimeException(RuntimeException e){
        log.error("统一的异常处理器",e);
        return ResultVO.ERR(ResultStatusEnum.COMMON_EXCEPTION);
    }
}
